import info
import subprocess

w = info.WebServer()

try:
  p = repr(subprocess.Popen(["reboot"], stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[1])

  print (w.add_html("Trying to reboot...", "h2"))
  print (w.add_html("If reboot doesn't occur within a few seconds, make sure server was started as root", "p"))
  print (w.add_html(p.strip("\'").replace("\\n", ""), "p"))
  print ("""<a href="/">Go back</a>""")

except OSError:
  print(w.add_html("Reboot failure", "h2"))
  print (w.add_html("Rebooting not supported for this machine", "p"))
  print ("""<a href="/">Go back</a>""")
  

# print w.do_popen(['reboot'])
# if w.do_popen(["reboot"]).find('Need to be root') != -1:
#   print(w.add_html("Reboot failed because server was not started as root", "p"))
#   print("""<a href="/">Go back</a>""")
# else:
#   print "yea"
#   print(w.add_html("Hi from reboot", "h1"))

